//
//  CustomerViewController.m
//  CommodityManager
//
//  Created by lanou3g on 15/5/28.
//  Copyright (c) 2015年 libertyair. All rights reserved.
//

#import "CustomerViewController.h"
#import "CustomerViewCell.h"

@interface CustomerViewController ()

@end

@implementation CustomerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
 self.navigationItem.title=@"客户管理";
    [self barButtonSet];
    
    //给搜索框回收键盘设置代理
    _searchCustomer.delegate=self;
    
   
    
    CustomerDetailViewController *customerDetailVC=[[CustomerDetailViewController alloc] init];
    customerDetailVC.sDelegate=self;
    
    self.customer=[[CustomerDetailModel alloc] init];
    //设置视图背景图片
   self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"34_bg_denglu"]]; 
    
}
#pragma mark-------------导航栏上的按钮设置
-(void)barButtonSet{
//左边按钮,返回主页
    UIBarButtonItem *leftBI=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-xiangzuo.png"] style:UIBarButtonItemStylePlain target:self action:@selector(returnMainVC:)];
    self.navigationItem.leftBarButtonItem=leftBI;
   //右边按钮,进入添加客户
    UIBarButtonItem *rightBI=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-jia.png"] style:UIBarButtonItemStylePlain target:self action:@selector(enterCustomerDetail:)];
    self.navigationItem.rightBarButtonItem=rightBI;


}
#pragma mark---------------保存客户信息的代理方法
-(void)saveCustomerDetailInform:(CustomerDetailModel *)customer{


    
}
#pragma mark----------------保存编辑后的客户信息
-(void)saveEditedCustomerDetailInform:(CustomerDetailModel *)customer IndexPath:(NSIndexPath *)index{


}



#pragma mark-------------左边按钮的点击事件,返回主页
-(void)returnMainVC:(UIBarButtonItem *)BI{

    [self.navigationController popToRootViewControllerAnimated:YES];
}
//右边按钮的点击事件,进入到新增客户页面
-(void)enterCustomerDetail:(UIBarButtonItem *)BI{
    CustomerDetailViewController *customerDetailVC=[[CustomerDetailViewController alloc] initWithNibName:@"CustomerDetailViewController" bundle:[NSBundle mainBundle]];
    customerDetailVC.sDelegate=self;
    [self.navigationController pushViewController:customerDetailVC animated:YES];
    
}
#pragma mark-----------------控制行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 125;
}
#pragma mark-----------------行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{


    return 20;
}
#pragma mark----------------显示cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    
   static NSString *customerCellIdentifier=@"customerCell";
   CustomerViewCell *cell=[tableView dequeueReusableCellWithIdentifier:customerCellIdentifier];
    if (cell==nil) {
        NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"CCell" owner:self options:nil ];
        cell=[nib objectAtIndex:0];
        
            }
  // NSUInteger row=[indexPath row];
   // NSLog(@"++++++++++++++ jonesduan %s, cell row:%lu", __func__, (unsigned long)row);
   
    UILabel *lableName=(UILabel *)[cell viewWithTag:101];
    lableName.text=_customer.cName;
    lableName.backgroundColor=[UIColor blueColor];
    UILabel *lablePhoneNum=(UILabel *)[cell viewWithTag:102];
    lablePhoneNum.text=_customer.cPhoneNum;
    lablePhoneNum.backgroundColor=[UIColor blueColor];
    UILabel *lableRemarks=(UILabel *)[cell viewWithTag:103];
    lableRemarks.text=_customer.cRemarks;
    lableRemarks.backgroundColor=[UIColor blueColor];

    return cell;
    
}

#pragma mark----关键方法，这个方法的实现决定了滑动删除功能的实现。内容可以为空
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
#pragma mark------------选中行的点击事件,实现的方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    CustomerDetailViewController *customerDetailVC=[[CustomerDetailViewController alloc] initWithNibName:@"CustomerDetailViewController" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:customerDetailVC animated:YES];

}
#pragma mark-------------搜索框回收键盘

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    
    [searchBar resignFirstResponder];
   
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/




@end
